package com.loveprogrammer.eternity.factory;

import com.alibaba.fastjson.JSON;
import com.loveprogrammer.eternity.model.affix.Affix;
import com.loveprogrammer.eternity.skill.State;
import com.loveprogrammer.eternity.skill.support.skills.AbstractSkill;
import com.loveprogrammer.eternity.skill.support.states.AbstractState;
import org.apache.commons.math3.ode.sampling.AbstractStepInterpolator;
import org.reflections.Reflections;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @version 1.0.0
 * @description: 状态工厂
 * @author: eric
 * @date: 2022-12-12 18:27
 **/
public class StateFactory {

    private static List<State> stateList = new ArrayList<>();
    private static Map<Integer, State> stateMap = new HashMap<>();

    static {
        Reflections reflections = new Reflections("com.loveprogrammer.eternity.skill.support.states.ignore");
        //Affix 是个接口，获取在指定包扫描的目录所有的实现类
        Set<Class<? extends State>> classes = reflections.getSubTypesOf(State.class);
        for (Class<? extends State > aClass : classes) {
            // System.out.println(aClass.getName());
            if(aClass.getName().contains("AbstractIgnore")){
                continue;
            }
            try {
                stateList.add(aClass.newInstance());
            } catch (InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        stateMap = stateList.stream().collect(Collectors.toMap(e -> e.id(),e->e));
    }


    public static State getById(int stateId) {
        return stateMap.get(stateId);
    }

    public static void main(String[] args) {
        State state = getById(99);
        System.out.println(state.name());
    }
}
